package com.xy.jm.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xy.common.annotation.DataSource;
import com.xy.common.enums.DataSourceType;
import com.xy.jm.entity.JmAuthenticateEntity;
import com.xy.jm.mapper.JmAuthenticateMapper;
import com.xy.jm.service.JmAuthenticateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Map;
@DataSource(value = DataSourceType.JM)
@Transactional(rollbackFor = Exception.class)
@Service
public class JmAuthenticateServiceImpl implements JmAuthenticateService {
    @Autowired
    private JmAuthenticateMapper jmAuthenticateMapper;
    @Override
    public Map<String, Object> page_authenticate_list(Integer current_page, Integer size) {
        QueryWrapper<JmAuthenticateEntity> qryWrapper = new QueryWrapper<>();
        qryWrapper.eq("authenticate_type",1);
        Page<JmAuthenticateEntity> page = new Page<>(current_page, size);
        IPage<JmAuthenticateEntity> list_page = jmAuthenticateMapper.selectPage(page, qryWrapper);
        Map<String,Object> data= new HashMap<>();
        data.put("Total",list_page.getTotal());
        data.put("pages",list_page.getPages());
        data.put("current_page",list_page.getCurrent());
        data.put("list",list_page.getRecords());
        return data;
    }

    @Override
    public JmAuthenticateEntity find_by_id(Integer id) {
        QueryWrapper<JmAuthenticateEntity> qryWrapper = new QueryWrapper<>();
        qryWrapper.eq("authenticate_id",id);
        return jmAuthenticateMapper.selectOne(qryWrapper);
    }
}
